package com.gem.day8;

import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class DemoDay8 {

	public static void main(String[] args) {
//1		double d=3.65;
//		BigDecimal bg1=new BigDecimal("3.11");
//		/*BigDecimal bg=new BigDecimal(String.valueOf(d));
//		BigDecimal bg1=new BigDecimal("3.14");
//		System.out.println(bg.add(bg1));*/
//		System.out.println(bg1.setScale(1,BigDecimal.ROUND_HALF_UP));
		
//2		Math
		/*System.out.println(Math.round(d));
		System.out.println((int)d);
		System.out.println(Math.ceil(d));
		System.out.println(Math.floor(d));
		System.out.println(Math.abs(d));
		System.out.println(Math.sqrt(Math.abs(d)));
		System.out.println(Math.pow(d,3));*/
//		System.out.println(Math.random());//[0.1)
		
//3		String
		
		
//		String s="中国";
		/*String s="hello";
		System.out.println(s.hashCode()+"-0");
		s=s+"world";
		System.out.println(s.hashCode()+"-1");
		s=s+"world";
		System.out.println(s.hashCode()+"-2");
		s=s+"world";
		System.out.println(s.hashCode()+"-3");*/
//		String s1=new String("hello");
//		
//		
//		System.out.println(s.hashCode()+"  "+s1.hashCode());
		/*String encoding=System.getProperty("file.encoding");
		System.out.println(encoding);
		byte[] b=null;
		try {
			b = s.getBytes("GBK");
		} catch (UnsupportedEncodingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	
		String s2=null;
		try {
			s2 = new String(b, "GBK");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println(s2);
		*/
		
//4		StringBuffer
		
		
//		StringBuffer sb=new StringBuffer();
//		sb=sb.append("hello");
//		StringBuffer sb1=new StringBuffer("hello");
//		System.out.println(sb1.hashCode());
//		sb1.append("world");
//		System.out.println(sb1.hashCode());
		
		/*String s4="hello";
		s4=s4+"world";
		String s4="hello";
		StringBuffer sb=new StringBuffer(s4);
		sb.append("world");
		s4=sb.toString();
		System.out.println(s4.length());*/
		
//		String s4="Hello";
//		String s5="hello";
//		System.out.println(s4.equals(s5));
//		System.out.println(s4.equalsIgnoreCase(s5));
//		
//		System.out.println(s4.toLowerCase().equals(s5.toLowerCase()));
//		
//		System.out.println(s4.concat(s5));//效率最好
//		System.out.println(s4+s5);//效率低
		
		//+  concat() 的区别
//		int num=12;
//		System.out.println(s4.concat(String.valueOf(num)));//s4+num
		
//		System.out.println(s4.lastIndexOf("l"));
//		System.out.println(s4.indexOf("l"));
//		System.out.println(s4.substring(1, 2));
//		for(int i=0;i<s4.length();i++){
//			String c=s4.substring(i, i+1);
//			System.out.println(c);
//		}
		/*
		StringBuffer sb2=new StringBuffer();
		sb2.append("hello");
		StringBuffer sb3=new StringBuffer("hello");
		
		System.out.println(sb2.length()+"   "+sb3.length());
		System.out.println(sb2.capacity()+"   "+sb3.capacity());
		
		sb2.append("12345678901112343434311");
		sb3.append("12345678901112343434311");
		System.out.println(sb2.length()+"   "+sb3.length());
		System.out.println(sb2.capacity()+"   "+sb3.capacity());
		sb2.trimToSize();
		sb3.trimToSize();
		System.out.println(sb2.length()+"   "+sb3.length());
		System.out.println(sb2.capacity()+"   "+sb3.capacity());
		
//		StringBuilder对象的效率最高、线程不安全
		StringBuilder sbd=new StringBuilder();
		sbd.append("abc");
		System.out.println(sbd.toString());*/
		
//5		Random 伪随机数类
//		Random rand=new Random(); 
		/*Random rand=new Random(50); 		//100 种子
		//[0,100) 这100个数字出现的概率是相同的，1%
		int num=rand.nextInt(100);//[0,100)
		System.out.println(num);
		double d=rand.nextDouble()*100;		//[0,1) 等价于 Math.random();
		System.out.println(d);
		rand.setSeed(109);
		int num1=rand.nextInt(100);//[0,100)
		System.out.println(num1);
		double d1=rand.nextDouble()*100;//[0,1) 等价于 Math.random();
		System.out.println(d1);*/
		
//6     Date Calendar
		Calendar c1=Calendar.getInstance();
		Date date=c1.getTime();
		SimpleDateFormat sformat=new SimpleDateFormat("MM-dd-yyyy");
		String newdaate=sformat.format(date);
		System.out.println(newdaate);
		System.out.println(c1.get(Calendar.MONTH));
		
//7		Pattern
		/*Pattern p=Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");
		Matcher ma=p.matcher("18512790420");
		boolean f=ma.matches();
		System.out.println(f);*/
		Pattern p=Pattern.compile("^[a-zA-Z]\\w{5}");
		Matcher ma=p.matcher("a12345d");
		boolean f=ma.matches();
		System.out.println(f);
		
		String s="a123dfsfa45d";
		/*String news=s.replaceAll("\\d", "");
		System.out.println(news);*/
	/*	String str[]=new String[s.length()];
		for (int i = 0; i < s.length(); i++) {
			str[i]=s.substring(i,i+1);
			
			System.out.println(str[i]);
		}*/
		char[] ch=s.toCharArray();
		for (char c : ch) {
			System.out.println(c);
		}
		for (int i = 0; i < ch.length; i++) {
			if(ch[i]>='0' &&ch[i]<='9'){
				ch[i]='\0';
			}
		}
		StringBuffer sb=new StringBuffer();
		
		for (int i = 0; i < ch.length; i++) {
			sb.append(ch[i]);
		}
		System.out.println(sb);
		
	}

}
